package com.allwees.bs.c.module.merchant.repository;

import com.allwees.bs.c.module.base.repository.BaseRepository;
import com.allwees.bs.c.module.merchant.entity.StoreEntity;
import com.allwees.bs.c.module.product.entity.ProductEntity;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;

import java.util.List;

public interface StoreRepository extends BaseRepository<StoreEntity, Integer> {
    @Modifying
    @Query(value = "update StoreEntity set total_collections=total_collections-1 where no in :nos")
    void incTotalCollectionsByIds(@Param("nos") List<String> nos);

    @Query("SELECT p FROM ProductEntity AS p where p.storeUuid = :storeUuid AND p.status = 0 AND p.createdAt > :afterTime ORDER BY p.createdAt DESC")
    List<ProductEntity> findStoreRecommendProducts(@Param("storeUuid") String storeUuid, @Param("afterTime") Long afterTime, Pageable pageable);

    StoreEntity getByUuid(String uuid);
}
